package Homework03;

/**
 * 本周作业：（必做）思考有多少种方式，在main函数启动一个新线程或线程池，
 * 异步运行一个方法，拿到这个方法的返回值后，退出主线程
 */
public class Answer1_3 {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        Sum sum = new Sum();
        Thread thread = new Thread(() -> {}, "t1");
        thread.start();
        sum.start();
        sum.join();
        Thread.sleep(1000);
        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");
    }
}

class Sum extends Thread {
    public void sum() throws InterruptedException {
        int result = fibo(36);
        System.out.println("异步计算结果为：" + result);
    }

    public int fibo(int a) {
        if (a < 2)
            return 1;
        return fibo(a - 1) + fibo(a - 2);
    }

    @Override
    public void run() {
        try {
            this.sum();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
